package com.ruoyi.common.mongo.service.impl;

import com.mongoplus.conditions.query.LambdaQueryChainWrapper;
import com.mongoplus.model.PageResult;
import com.mongoplus.service.impl.ServiceImpl;
import com.ruoyi.common.mongo.domain.Record;
import com.ruoyi.common.mongo.domain.bo.RecordBo;
import com.ruoyi.common.mongo.service.IRecordService;
import com.ruoyi.common.utils.StringUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 识别记录处理业务层 impl
 * @Author: 陈江灿
 * @CreateTime: 2025-02-14
 */
@Service
@RequiredArgsConstructor
@Slf4j
public class RecordServiceImpl extends ServiceImpl<Record> implements IRecordService {

    /**
     * 人脸识别记录列表
     * @param bo
     * @param pageSize
     * @param pageNum
     * @return
     */
    @Override
    public PageResult<Record> queryPageList(RecordBo bo, Integer pageSize, Integer pageNum) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryChainWrapper<Record> lwq = this.lambdaQuery();
        lwq.eq(StringUtils.isNotEmpty(bo.getPersonId()), Record::getPersonId, bo.getPersonId());
        lwq.like(StringUtils.isNotEmpty(bo.getName()), Record::getName, bo.getName());
        lwq.eq(StringUtils.isNotEmpty(bo.getType()), Record::getType, bo.getType());
        String sn = bo.getSn();
        if (StringUtils.isEmpty(sn)) {
            lwq.eq(StringUtils.isNotEmpty(sn), Record::getSn, sn);
        }
        if (bo.getBeginCreateTime() != null && bo.getEndCreateTime() != null) {
            lwq.between(true, Record::getCreatedAt, bo.getBeginCreateTime(), bo.getEndCreateTime(), false);
        }
        lwq.orderByDesc(Record::getCreatedAt);
        PageResult<Record> page = this.page(lwq, pageNum, pageSize);
        return page;
    }
}
